*******************************
* IRCA and Redistricting
* Navid Sabet and Noam Yuchtman
* Table C1: Figure 6 in table form.
*******************************

//Setup
	do "$dofiles/00_setup.do"

//Load master data
	use irca_gerrymander.dta, clear
	
	//Controls
	global controls  c.pop1990#i.p102 c.inc_pc1990#i.p102  c.age_share1990#i.p102 c.unemployment_1990#i.p102 c.educ1990##i.p102 c.births_1990#i.p102 c.black_share1990#i.p102 c.white_share1990#i.p102
	
	global controls_full  c.pop1990##i.p102##i.legal_control_kaplan1991 c.inc_pc1990##i.p102##i.legal_control_kaplan1991  c.age_share1990##i.p102##i.legal_control_kaplan1991 c.unemployment_1990##i.p102##i.legal_control_kaplan1991 c.educ1990##i.p102##i.legal_control_kaplan1991 c.births_1990##i.p102##i.legal_control_kaplan1991 c.black_share1990##i.p102##i.legal_control_kaplan1991 c.white_share1990##i.p102##i.legal_control_kaplan1991
	
	//VRA Controls: first one is VRA horse race v IRCA; second is horse race of VRA v. Legal Controls.
	global vra_control i.vra_covered##i.p102
	global vra_full i.vra_covered##i.p102##i.legal_control_kaplan1991 
	
	//Extra controls
	global extras c.povrate_1990#i.p102 c.hsd_share1990#i.p102 c.spr010_1990#i.p102 c.spr030_1990#i.p102 c.housing_value_1990#i.p102 c.crime_1990#1.p102
	
	 //1980 Controls
	global controls1980 c.population_bea1980#i.p102 c.income_pc1980#i.p102  c.age_share1980#i.p102 c.edu6351980#i.p102 c.births_1980#i.p102 c.black_share1980#i.p102 c.white_share1980#i.p102
	
	//Controls pre post 1980 redistricting.
	global controls97 c.pop1990#i.p97 c.inc_pc1990#i.p97  c.age_share1990#i.p97 c.unemployment_1990#i.p97 c.educ1990##i.p97 c.births_1990#i.p97 c.black_share1990#i.p97 c.white_share1990#i.p97
		
	//Vra controls: pre post 1980 redistricting
	global vra_control97 i.vra_covered##i.p97
	
	//Fixed effects
	global fe id congress#StateFIPS c.hisp_share1980#i.congress i.unassigned_county#i.congress 
	
	//Clustering
	global cluster id

	
****************
* Poslpy Popper Panel
****************
eststo clear
	 //Baseline
	reghdfe pp_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //No controls
	reghdfe pp_county c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Extra controls
	reghdfe pp_county $controls $vra_control $extras c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//1980 Controls
	reghdfe pp_county $controls1980 $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)	
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 	
	
	//Interacted Observables (Fully Saturated)
	reghdfe pp_county $controls_full $vra_full c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Alternative definition of legal control
	reghdfe pp_county $controls $vra_control c.irca_std##i.p102##ib2.arp_nocommission [weight = cuts] , a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Using Hispanic share instead of imputing
	reghdfe pp_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop imputed counties
	reghdfe pp_county $controls $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //Only single district counties
	reghdfe pp_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop minority-majority counties
	reghdfe pp_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight = cuts] if hisp_majority_county==0 & black_majority==0, a($fe) cluster($cluster)
	sum pp_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Falsification
	reghdfe pp_county $controls97 $vra_control97 c.irca_std##i.p97##ib2.legal_control_kaplan1981 [weight = cuts], a($fe) cluster($cluster)
	sum pp_county if e(sample) & p97==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	 

			
esttab 	using "${output}/panel_pp.tex", replace booktabs fragment  /// 
			label nomtitles nonumbers noobs nonote nogaps noline  ///
			se star(* 0.1 ** 0.05 *** 0.01) sfmt(%9.2fc) ///
				rename(1.p102#c.irca_pc1990_hisp_std 1.p102#c.irca_std ///
				1.p102#0.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102#0.legal_control_kaplan1991#c.irca_std ///
				1.p102#1.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102#1.legal_control_kaplan1991#c.irca_std ///
				1.p97#c.irca_std 1.p102#c.irca_std ///
				1.p97#0.legal_control_kaplan1981#c.irca_std 1.p102#0.legal_control_kaplan1991#c.irca_std ///
				1.p97#1.legal_control_kaplan1981#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std ///
				1.p102#1.arp_nocommission#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std) ///
			keep(1.p102#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std) ///
			scalars("ymean $\bar{Y}_{Pre}$" "ysd $[S.D.]$") 

			//// \hspace{.5em} IRCA$_{90}$ $\times$ Post $\times$ D /// 
			/// \multicolumn{1}{|c}{	
			/// \cmidrule(lr){2-8} \cmidrule(lr){9-12}
			// \multicolumn{7}{c}{
	
			
****************
* Reock Panel
****************
eststo clear
	 //Baseline
	reghdfe reo_county $controls $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)	
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //No controls
	reghdfe reo_county c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Extra controls
	reghdfe reo_county $controls $vra_control $extras c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//1980 Controls
	reghdfe reo_county $controls1980 $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)	
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 	
	
	//Interacted Observables (Fully Saturated)
	reghdfe reo_county $controls_full $vra_full c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Alternative definition of legal control
	reghdfe reo_county $controls $vra_control c.irca_std##i.p102##ib2.arp_nocommission [weight = cuts] , a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Using Hispanic share instead of imputing
	reghdfe reo_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop imputed counties
	reghdfe reo_county $controls $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 if unassigned_county == 0  [weight = cuts], a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //Only single district counties
	reghdfe reo_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //Drop minority-majority counties
	reghdfe reo_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight = cuts] if hisp_majority_county==0 & black_majority==0, a($fe) cluster($cluster)
	sum reo_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Falsification
	reghdfe reo_county  $controls97 $vra_control97 c.irca_std##i.p97##ib2.legal_control_kaplan1981 [weight = cuts] , a($fe) cluster($cluster)
	sum reo_county if e(sample) & p97==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
			

			 
esttab 	using "${output}/panel_reo.tex", replace booktabs fragment  /// 
			label nomtitles nonumbers noobs nonote nogaps noline  ///
			se star(* 0.1 ** 0.05 *** 0.01) sfmt(%9.2fc) ///
				rename(1.p102#c.irca_pc1990_hisp_std 1.p102#c.irca_std ///
				1.p102#0.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102#0.legal_control_kaplan1991#c.irca_std ///
				1.p102#1.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102#1.legal_control_kaplan1991#c.irca_std ///
				1.p97#c.irca_std 1.p102#c.irca_std ///
				1.p97#0.legal_control_kaplan1981#c.irca_std 1.p102#0.legal_control_kaplan1991#c.irca_std ///
				1.p97#1.legal_control_kaplan1981#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std ///
				1.p102#1.arp_nocommission#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std) ///
			keep(1.p102#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std) ///
			scalars("ymean $\bar{Y}_{Pre}$" "ysd $[S.D.]$") 

		//// \hspace{.5em} IRCA$_{90}$ $\times$ Post $\times$ D  
			/// \multicolumn{1}{|c}{	
			/// \cmidrule(lr){2-8} \cmidrule(lr){9-12}
			/// \multicolumn{7}{c}{
				
***********************
*	Generate Table
**********************		
estfe est* // push FEs information from absorb argument in reghdfe command		
esttab  est*	using "${output}/tabc1.tex", replace booktabs ///
				nonote noobs nogaps compress noeqlines se drop(*) substitute(_ _)  ///
				mgroups("Empirical Specifications" "Sample Restrictions" "Placebo", pattern(1 0 0 0 0 0 0 1 0 0 1) ///
				prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
				mtitles("\makecell{Baseline \\ Model}" "\makecell{No \\ Covariates}" "\makecell{Extra \\ Covariates}" "\makecell{1980 \\ Covariates}" "\makecell{Interacted \\ Observables}" "\makecell{Alternative \\ Legal Control}" "\makecell{Hispanic \\ Impute}" "\makecell{Drop \\ Imputed}" "\makecell{Single-District \\ Counties}" "\makecell{Drop MM \\ Districts}" "\makecell{1980 \\ Placebo}") ///
				posthead( ///
				\midrule \multicolumn{@span}{l}{\emph{Panel A. Polsby-Popper}} \\ ///
					\input{${output}/panel_pp.tex} ///
					\midrule \multicolumn{@span}{l}{\emph{Panel B. Reock}} \\ ///
					\input{${output}/panel_reo.tex}  ) ///
				scalars("N $N$" "clusters Clusters") sfmt(%9.3gc) ///
				star(* 0.1 ** 0.05 *** 0.01) 				

			

